<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>


<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <base href="<%=basePath%>">
    
    <title>园林绿植管理首页</title>
 
	<jsp:include page="../../include.jsp"></jsp:include>
	<link href="./resource/css/dashboard.css" rel="stylesheet">
	<link href="./resource/css/index.css" rel="stylesheet">
	<!-- 青色 #389a57 #59be7b  cff1da 红褐色 #41182a #683047 黑色 #00264c-->
    <style type="text/css">
    </style>
  </head>
 
  <body>
  
		  <div class="modal fade" id="addOrEditDialog" tabindex="-1" role="dialog" aria-labelledby="model" data-backdrop="static">
		     <div class="modal-dialog" role="document">
		       <div class="modal-content">
		         <!-- content -->
		       </div>
		     </div>
		  </div>
	      <h2 class="page-header">园林绿植信息</h2>
	      <form class="navbar-form navbar-left">
			  <div id="toolbar">
	            <select class="form-control">
	               <option value="">导出当前页</option>
	               <option value="all">导出全部</option>
	               <option value="selected">导出选择项</option>
	            </select>
	          </div>
        <button type="button" class="btn btn-default" name="newEntity"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> 添加</button>
        <button type="button" class="btn btn-default" name="delEntity"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> 删除</button>
		  </form>
          <!--  <table id="table"></table> -->
          <table id="table"
                 data-toggle="table"
                 data-cache="false"
                 data-striped="true" 
                 data-show-columns="true"
                 data-show-toggle="true"
                 data-show-pagination-switch="true"
                 data-show-export="true"
                 data-show-refresh="true"
                 data-height="526"
                 data-pagination="true"
                 data-search="true"
                 data-key-events="true"
                 data-detail-view="true"
                 data-detail-formatter="detailFormatter"
                 data-click-to-select="true"
                 data-toolbar="#toolbar"
                 data-click-to-select="true"
                 data-sort-name="id"
                 data-sort-order="asc"
                 data-method="post"
                 data-unique-id="id"
                 data-url="plantController/getAllData"
                 >
              <thead>
              <tr>
                <th data-field="state" data-checkbox="true"></th>
                <th data-sortable="true" data-formatter="indexFormatter" data-width="5%">序号</th>
                <th data-field="id"   data-visible="false" data-switchable="false">ID</th>
                <th data-field="name" data-sortable="true" data-width="10%">名称 </th>
                <th data-field="code" data-sortable="true" data-width="10%">编码</th>
                <th data-field="projectName" data-sortable="true" data-width="10%">所属项目</th>
                <th data-field="category" data-sortable="true" data-width="10%">所属种类</th>
                <th data-field="type" data-sortable="true" data-width="10%">类型</th>
                <th data-field="status" data-sortable="true" data-width="10%">状态</th>
                <th data-field="price" data-sortable="true" data-width="10%">价格</th>
                <th data-field="prodDate" data-sortable="true" data-width="10%" data-formatter="dateFormatter">生产日期</th>
                <th data-field="descriptions" data-sortable="true" data-width="15%">描述</th>
              </tr>
              </thead>
          </table>
          
          <script type="text/javascript">
          
           /********************* js table **************************/
           var path = "<%=path%>";
           var $table = $('#table');
           var ids = new Array();
           
           $(function () {
        	  
        	  //export table
              $('#toolbar').find('select').change(function () {
                  $table.bootstrapTable('destroy').bootstrapTable({
                      exportDataType: $(this).val()
                  });
              });
              
        	 //console table
              $('#table').on("load-success.bs.table",function(e,data){
            	  /* console.log(data); */
              });
        	 
              //table edit 
              $('#table').on("dbl-click-row.bs.table",function(e,data){
            	 // alert('getRowByUniqueId: ' + JSON.stringify($table.bootstrapTable('getRowByUniqueId',data.id)));
      	         var url = path +'/plantController/view/edit?id='+data.id;
       	         showModal(url); 
              });
              
              //model hidden
              $('#addOrEditDialog').on("hidden.bs.modal", function() {
            	    $(this).removeData("bs.modal");
            	    $(".modal-content").children().remove();
            	});
              
           });

           //table add
        	 $('button[name="newEntity"]').click(function (){
     	         var url = path +'/plantController/view/new';
        	     showModal(url);
     	     }); 
           
            
           //table delete
        	 $('button[name="delEntity"]').click(function (){

        	   ids = getSelectedRowsId();

        	   if (!ids || ids.length <= 0) {
        	     bootbox.alert("请选择操作的目标!");
        	   }else{
        		    bootbox.confirm('此操作将会级联删除其关联的所有数据，确定要删除吗?',function(result){
                    if(result) { 

                  	  params= $.each(ids,function(index,id){return 'id='+ id;}).join('&id=');

                      var url = path + '/plantController/del?id=' + params;
                      $.post(url, function (result){
                    	  if(result.status){
	                    	  $.toast({
    	  		        		    text: result.message,
    	  		        		    hideAfter : 1500,  
    	  		        		    stack : 1,  
    	  		        		    showHideTransition: 'slide',
    	  		        		    icon: 'success',
    	  		        		    textAlign : 'center',
    	  		        		    position : 'top-right'
    	  		        		  })
  		        		 	      $table.bootstrapTable('refresh');
                        }else{
                          	$.toast({
        		        		    text: result.message,
        		        		    hideAfter : 1500,  
        		        		    stack : 1,  
        		        		    showHideTransition: 'slide',
        		        		    icon: 'error',
        		        		    textAlign : 'center',
        		        		    position : 'top-right'
        		        		  })
                        }
                      }); 
                    }
                });
        	    }
     	     });
            
           function getSelectedRowsId(){
        	 ids = [];    
             $.each($table.bootstrapTable('getSelections'),function(index,value) {
 	         	    ids.push(value.id);
 	           }); 
                
              return ids;
           }
           
           /********************* js basic **************************/
           //show modal
           function showModal(url, callback){
              $.get(url, function (data){
                var modal = $('#addOrEditDialog');
                var modal_content =  modal.find('.modal-content');
                modal_content.html(data);
                if(callback){
                	callback();
                }
                modal.modal('show');
              });
            }
          
          </script>

  </body>
</html>
